package com.cty.controller;

import com.cty.pojo.Schedule;
import com.cty.service.ScheduleService;
import com.cty.utils.R;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@CrossOrigin //允许不同源的地址访问
@Controller
@ResponseBody
@RequestMapping("schedule")
@Slf4j //日志
public class ScheduleController {

    @Autowired
    ScheduleService scheduleService;

    @GetMapping("{pageSize}/{currentPage}")
    public R showList(@PathVariable int pageSize,
                      @PathVariable int currentPage) {
        R r = scheduleService.page(pageSize,currentPage);
        log.info("得到的数据: {}",r); //输出日志
        return r;
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id) {
        R delete = scheduleService.delete(id);
        return delete;
    }

    @PostMapping
    public R save(@RequestBody Schedule schedule) {
        R save = scheduleService.save(schedule);
        return save;
    }

    @PutMapping
    public R update(@RequestBody Schedule schedule){
        R update = scheduleService.update(schedule);
        return update;
    }
}
